<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	建造者模式与工厂模式相比，相同点是都是为了创建对象。区别是：工厂模式只关心结果。建造者模式更关心过程。
	<body>
	</body>
	<script type="text/javascript">
		//创建一位人类
		var Human = function(param) {
			//技能
			this.skill = param && param.skill || '保密';
			//兴趣爱好
			this.hobby = param && param.hobby || '保密';
		}
		//类人原型方法
		Human.prototype = {
			getSkill: function() {
				return this.skill;
			},
			getHobby: function() {
				return this.hobby;
			}
		}
		//实例化姓名类
		var Named = function(name) {
			var that = this;
			//构造器
			//构造函数解析姓名的姓与名
			(function(name, that) {
				that.wholeName = name;
				if(name.indexOf(' ') > -1) {
					that.FirstName = name.slice(0, name.indexOf(' '));
					that.secondName = name.slice(name.indexOf(' '));

				}
			})(name, that);
		}

		//实例化职位类
		var Work = function(work) {
			var that = this;
			//构造器
			//构造函数中通过传入的职位特征来设置相应职位以及描述
			(function(work, that) {
				switch(work) {
					case 'code':
						that.work = '工程师';
						that.workDescript = '构建世界';
						break;
					case 'UI':
						that.work = 'UI设计师';
						that.workDescript = '简易、清楚、符合习惯';
					default:
						that.work = work;
						that.workDescript = '描述未知'
				}
			})(work,that);
		}
		//更换期望的职位
		Work.prototype.changeWork = function(work) {
			this.work = work;
		}
		//添加对职位的描述
		Work.prototype.changeDescript = function(workDescript) {
			this.workDescript = workDescript;
		}
		
		/*应聘者建造者
		 * 参数name:姓名（全名）
		 * 参数work:期望职位
		 * */
		var Person = function(name,work){
			//创建应聘者缓存对象
			var _person = new Human();
			//创建应聘者姓名解析对象
			_person.name=new Named(name);
			//创建应聘者期望职位
			_person.work = new Work(work);
			//将创建的应聘者对象返回
			return _person;
		}
		var person = new Person('xiao ming','code');
		console.log(person.skill);//保密
		console.log(person.name.FirstName);//xiao
		console.log(person.work.work);//工程师
		console.log(person.work.workDescript);//构建世界
		person.work.changeDescript('修改职位描述')
		console.log(person.work.workDescript);//01书.html?__hbt=1645626806648:93 修改职位描述
	</script>

</html>